home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-13
/
me_cd22.zip
/
MUTT2.ZIP
/
DIR.MUT
< prev
next >
Wrap
Text File
|
1992-04-27
|
4KB
|
142 lines
;; dir.mut : directory stack stuff for UNIX versions of ME
;; pgms defined:
;; - cd : Change the current directory.
;; - dirs : Show the contents of the directory stack. The top (or left
;; most) entry is the current directory, next is the directory you
;; left to get to the current directory.
;; - pwd : Show the current directory.
;; - pu : Change the current directory, using the stack to save the
;; changes.
;; (pu directory) pushes the current directory on the stack and sets
;; the current directory to directory.
;; (pu "") swaps the top 2 entries on the stack.
;; (pu +n) swaps the top of the stack with the nth stack item. n
;; starts at zero.
;; - po discards the top entry on the stack and sets the current
;; directory to the new top of stack.
;; C Durland 10/87, 5/88 Public Domain
(include me2.h)
(const stack-size 10) ; the max number of entries on the directory stack
(small-int num-stack-entries)
(defun
init-dirstack MAIN { (clear-stack) (push (sub~ (current-directory))) }
cd
{
(if (current-directory (complete CC_FNAME "change directory to: "))
{
(pop) ;; nuke the first entry to make room for this one
(msg "moved to " (push (sub~ (current-directory))))
TRUE
}
{ (msg "Not a valid directory") FALSE })
}
pwd { (msg "current directory: " (sub~ (current-directory))) }
pu ;; push directory
{
(string name name2)
(int n)
(name (complete CC_FNAME "pushd to: "))
(if (== name "") ; swap top 2 items on stack
{
(if (< num-stack-entries 2)
{ (msg "directory stack too small to swap") FALSE (done) })
(name (pop)) (name2 (pop))
(push name) (push name2)
(cd name2)
(done)
})
(if (== (extract-element name 0) "+") ; +n => move (n+1)th entry to top
{
(n (convert-to NUMBER (extract-elements name 1 10000)))
(if (>= n num-stack-entries)
{ (msg "Only got " num-stack-entries " entries")(done) })
(name (popn n))
(push name) ;; push a dummy that is nuked my (cd)
(cd name)
(done)
})
(if (current-directory name) ;; directory exists
{
(if (>= num-stack-entries stack-size) ;; shrink stack
(popn (- num-stack-entries 1)))
(msg "moved to " (push (sub~ (current-directory))))
TRUE
}
{ (msg "Not a valid directory") FALSE })
}
po ;; pop directory
{
(if (< num-stack-entries 2) { (msg "directory stack empty") FALSE (done) })
(pop)
(cd (peek 0))
}
sub~ (string dir-name) HIDDEN ; convert /users/craig/... to ~/...
{
(int n)
(n (length-of (getenv "HOME")))
(if (and (!= n 0) (== (getenv "HOME") (extract-elements dir-name 0 n)))
(concat "~" (extract-elements dir-name n 1000))
dir-name
)
}
)
(defun
MAIN
{
(require "popup") ;; for (dirs)
}
dirs
{
(int j)
(menu-box
">Directory Stack"
"-"
(for (j 0) (< j num-stack-entries)(+= j 1) (push-arg (peek j)))
)
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; Stack Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(list dir-stack)
(defun
clear-stack HIDDEN
{
(while (!= 0 num-stack-entries) (pop))
}
push (string dir) HIDDEN ;; returns name
{
(insert-object dir-stack -1 dir)
(num-stack-entries (length-of dir-stack))
dir
}
peek (int n) HIDDEN { (extract-element dir-stack n) }
popn (int n) HIDDEN
{
(string dir)
(dir (extract-element dir-stack n))
(remove-elements dir-stack n 1)
(num-stack-entries (length-of dir-stack))
dir
}
pop HIDDEN { (popn 0) }
)